<?php

include("global.php");

$pagetitle=" - Administration - User Levels";
$links=" > Administration > User Levels";

include ("header.php");

include ("admin_header.php");

if($userloggedinarray[15]!=="administrator"){
   unset($tplcontent);
   $tplcontent['notice']="Must be logged in as administrator to use control panel!";
   echo template('notice',$tplcontent);
}else{

if(!$adduserlevels&&!isset($edituserlevels)&&!isset($deleteuserlevels)&!$adduserlevels2&&!isset($edituserlevels2)){
 unset($tplcontent);
 $userlevelsarray=getdata("$configarray[5]/userlevels.php");

   if($configarray[45]!=="on"){
    $tplcontent['imageiconnotice']="NOTE: User level image icons are enabled, this means the name you give the level will not mean anything<br>";
   }

   for($n=0;$n<count($userlevelsarray);$n+=2){

    $tplcontent['userlevelslist'].="<b>$userlevelsarray[$n] -> ".$userlevelsarray[$n+1]."</b>\n";
    $tplcontent['userlevelslist'].=" | <a href=\"admin_userlevels.php?edituserlevels=$n\">Edit</a>";
    $tplcontent['userlevelslist'].=" | <a href=\"admin_userlevels.php?deleteuserlevels=$n\">Delete</a>";

    $tplcontent['userlevelslist'].="<br><br>";

   }//end userlevels loop

   $tplcontent['addnew'].="<a href=\"admin_userlevels.php?adduserlevels=1\">Add new</a>";

 echo template('adminuserlevelsview',$tplcontent);
 }

 if(isset($edituserlevels)){

 $userlevelsarray=getdata("$configarray[5]/userlevels.php");

 $tplcontent['formheader'].="<form action=\"admin_userlevels.php\" method=post>";

 $tplcontent['formheader'].="<input type=hidden name=\"edituserlevels2\" value=\"$edituserlevels\" size=40>";

 $tplcontent['userlevelid'].="Edit User Level $edituserlevels";

 $tplcontent['userlevelname'].="<input type=text name=\"userlevelname\" value=\"$userlevelsarray[$edituserlevels]\" size=40 class=\"forminput\">";
 $tplcontent['poststoachieve'].="<input type=text name=\"userlevelposts\" value=\"".$userlevelsarray[$edituserlevels+1]."\" size=5 class=\"forminput\">";

 $tplcontent['submitbutton'].="<input type=submit name=\"submit\" value=\"Update\" class=\"formbutton\">";

 $tplcontent['formfooter'].="</form>";

 echo template('adminuserleveledit',$tplcontent);
 }

 if(isset($edituserlevels2)){

 writedata("$configarray[5]/userlevels.php",$userlevelname,$edituserlevels2);
 writedata("$configarray[5]/userlevels.php",$userlevelposts,$edituserlevels2+1);

   unset($tplcontent);
   $tplcontent['notice']="User level edited - <a href=\"admin_userlevels.php\">Back to listing</a>";
   echo template('notice',$tplcontent);

 }

 if($adduserlevels=="1"){

 $tplcontent['formheader'].="<form action=\"admin_userlevels.php\" method=post>";
 $tplcontent['formheader'].="<input type=hidden name=\"adduserlevels\" value=\"2\" size=40>";

 $tplcontent['userlevelname'].="<input type=text name=\"userlevelname\" size=40 class=\"forminput\">";
 $tplcontent['poststoachieve'].="<input type=text name=\"userlevelposts\" size=5 class=\"forminput\">";

 $tplcontent['submitbutton'].="<input type=submit name=\"submit\" value=\"Add\" class=\"formbutton\">";

 $tplcontent['formfooter'].="</form>";
 
 echo template('adminuserleveladd',$tplcontent);
 }

 if($adduserlevels=="2"){
 $userlevelsarray=getdata("$configarray[5]/userlevels.php");
 $end=count($userlevelsarray);

 writedata("$configarray[5]/userlevels.php",$userlevelname,$end);
 writedata("$configarray[5]/userlevels.php",$userlevelposts,$end+1);

   unset($tplcontent);
   $tplcontent['notice']="User level added - <a href=\"admin_userlevels.php\">Back to listing</a>";
   echo template('notice',$tplcontent);

 }

 if(isset($deleteuserlevels)){
 deletedata("$configarray[5]/userlevels.php",$deleteuserlevels);
 deletedata("$configarray[5]/userlevels.php",$deleteuserlevels);

   unset($tplcontent);
   $tplcontent['notice']="User level $deleteuserlevels deleted - <a href=\"admin_userlevels.php\">Back to listing</a>";
   echo template('notice',$tplcontent);

 }

}
include("admin_footer.php");

include("footer.php");

?>
